package com.edu.javaweb.controller;

import com.edu.javaweb.pojo.Admin;
import com.edu.javaweb.pojo.Student;
import com.edu.javaweb.pojo.StudentRecord;
import com.edu.javaweb.service.StudentRecordService;
import com.edu.javaweb.service.StudentService;
import com.edu.javaweb.vo.CGAdminVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class StudentController {
    @Autowired
    private StudentRecordService studentRecordService;
    @Autowired
    private StudentService studentService;
    @RequestMapping("/student/cgStudentPassword")
    @ResponseBody
    public void cgStudentPassword(CGAdminVo cgAdminVo){
        Student student = studentService.getStudent(cgAdminVo.getAccount());
        if (student.getPassword().equals(cgAdminVo.getOldPassword())){
            student.setPassword(cgAdminVo.getNewPassword());
            studentService.cgStudentPassword(student);
        }
    }
    @RequestMapping("/student/stuSubmit")
    @ResponseBody
    public void stuSubmit(StudentRecord studentRecord, HttpSession session){
        studentRecordService.insStuRecord(studentRecord,session);
    }
    @RequestMapping("/student/stuHisRecord")
    @ResponseBody
    public List<StudentRecord> stuHisRecord(HttpSession session){
        return studentRecordService.stuHisRecord(session);
    }
}
